// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {
    ccclass,
    property
} = cc._decorator;
import {Gardener, GardenerMessageBox, IGardenerMessageBox} from "../gardener/GameGardener"

@ccclass
export default class MessageBox extends GardenerMessageBox implements IGardenerMessageBox {

    @property(cc.Label)
    lbMessage: cc.Label = null;

    _confirmCallback: Function;
    _cancelCallback: Function;
    _closeCallback: Function;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    showMessage(content) {
        this.lbMessage.string = content;
    }

    start() {

    }

    onBtnComfirm_Tap() {
        this._confirmCallback && this._confirmCallback();
        this.close();
    }

    onBtnCancel_Tap() {
        this._cancelCallback && this._cancelCallback();
        this.close();
    }

    onBtnClose_Tap() {
        this._closeCallback && this._closeCallback();
        this.close();
    }

    close() {
        Gardener.closeMessageBox(this.node);
    }

    // update (dt) {},

    display() {
        GameLogger.debug('msg box display');
    }

    dispose() {
        GameLogger.debug('msg box dispose');

        this._confirmCallback = null;
        this._cancelCallback = null;
        this._closeCallback = null;
        this.node.isValid && this.node.destroy();
    }
}